<?php
	include "public/commom/config.php";//引入配置连接数据库文件
	
	if($_POST) {
		$account = $_POST["account"];//账号
		$password1 = $_POST["password"];//密码
		
		$sql = "SELECT * FROM user WHERE account = '$account'";//sql语句 - 查找该账号记录
		
		$result = mysqli_query($conn, $sql);//result - 执行sql语句
	    
	    if(mysqli_num_rows($result)) {//该账号是否存在
	    	//true
	    	while($row = mysqli_fetch_array($result)) {//循环
	    		$password2 = $row["password"];//该账号的密码
	    		
	    		if($password1 == $password2) {
	    			//true
	    			$_SESSION["user_id"] = $row["id"];//用户id
	    			$_SESSION["username"] = $row["username"];//昵称
	    			$_SESSION["headportrait"] = $row["headportrait"];//头像
	    			
	    			mysqli_close($conn);//关闭数据库连接
	    			
		    		header("Location: ./index.php");//跳转页面
		    	} else {
		    		//false
		    		echo "密码错误";
		    	}
	    	}
	    } else{
	    	//false
	    	echo "账号不存在";
	    }
	}
?>